/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tutor;

import ejb.GestioneFileLocal;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import jpa.Documento;

/**
 *
 * @author Administrator
 */
@ManagedBean(name = "TrovaFile")
@SessionScoped
public class TrovaFile {

    @EJB
    GestioneFileLocal gf;
    private String termine;
    private String cercaPer;
    private List<Documento> result;
    private String message;

    /**
     * Creates a new instance of RicercaArticolo
     */
    public TrovaFile() {
    }

    public String getTermine() {
        return termine;
    }

    public void setTermine(String termine) {
        this.termine = termine;
    }

    public String getCercaPer() {
        return cercaPer;
    }

    public void setCercaPer(String cercaPer) {
        this.cercaPer = cercaPer;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Collection<Documento> getResult() {
        if (result != null) {
            return Collections.unmodifiableCollection(result);
        }
        return null;
    }

    public void setResult(List<Documento> result) {
        this.result = result;
    }

    public String getMessage() {
        return message;
    }

    public String cerca() {
        result = gf.ricerca(termine, cercaPer);
        if (result.isEmpty()) {
            message = "La ricerca non ha prodotto risultati";
            return "no";
        }
        message = "";
        return "si";
    }
}
